﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using Data;
using Business;

namespace prototypes
{
    public partial class BuscarClienteReserva : Form
    {
        private DataTable dataTableTemporal = new DataTable();
        public BuscarClienteReserva()
        {
            InitializeComponent();
        }

        private void BTBuscar_Click(object sender, EventArgs e)
        {
            DGDatosPersonal.Columns.Clear();
            if (TBBuscar.Text != "")
            {
                TBBuscar.Text = Regex.Replace(TBBuscar.Text, @"\s+", " ");
                ClienteDataAccess buscarDataAccess = new ClienteDataAccess();
                dataTableTemporal = buscarDataAccess.buscarDatosLimitado(TBBuscar.Text.Trim());
                DGDatosPersonal.DataSource = dataTableTemporal;
            }
        }

        private void BTCancelar_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void BTAceptar_Click(object sender, EventArgs e)
        {
            try
            {
                int fila = DGDatosPersonal.CurrentRow.Index;
                if (fila != -1)
                {
                    DialogResult=DialogResult.OK;
                    numeroDocumento = DGDatosPersonal.Rows[fila].Cells["numeroDocumento"].Value.ToString();
                    this.Close();
                }
            }
            catch (SystemException exeption)
            {
            }
        }

        public string numeroDocumento { get; set; }

        private void TBBuscar_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Validador.validarLetraConEspacio(e.KeyChar))
                e.Handled = false;
            else
                e.Handled = true;
        }
    }
}
